package cn.tedu.utils;/**
 * @Author 金帮嘉诚 @Date 2021-07-15 星期四 19:00
 */
/*本类用于测试*/

import cn.tedu.pojo.Student;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Arrays;

/**
 * 知识点
 */
public class StuTb {
    public static Student insert(Student student) {
        Connection conn = null;
        PreparedStatement ps = null;
        ResultSet rs = null;

        try {
            conn = Jdbc.getCon();
            //    id 姓名 年龄 性别 爱好 学历 入学日期
            String sql = "insert into spb_student2 values(null,?,?,?,?,?,?)";
            ps = conn.prepareStatement(sql);
            ps.setString(1, student.getUser());
            ps.setInt(2, student.getAge());
            ps.setInt(3, student.getSex());
            ps.setString(4, Arrays.toString(student.getHobby()));
            ps.setInt(5, student.getEdu());

            long utilDateL = student.getInTime().getTime();
            java.sql.Date sqlDate = new java.sql.Date(utilDateL);
            ps.setDate(6, sqlDate);


            if (ps.executeUpdate() == 1) {
                System.out.println("插入成功");
            } else {
                System.out.println("插入失败");
            }

        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        } finally {
            Jdbc.closeRPC(rs, ps, conn);
        }

        return student;
    }
}
